use env_logger::Builder;
use std::fs::OpenOptions;
use std::io::Write;

pub fn init_logger() {
 // Create or open debug log file
    let debug_file = OpenOptions::new()
        .create(true)
        .write(true)
        .truncate(true)
        .open("debug.log")
        .unwrap();

 // Configure log output to file
    Builder::new()
        .format(|buf, record| {
            let file = record.file().unwrap_or("unknown");
            let file = file.split("\\").last().unwrap_or(file);
            writeln!(buf, "[{}] [{}] {}", record.level(), file, record.args())
        })
        .target(env_logger::Target::Pipe(Box::new(debug_file)))
        .filter_level(log::LevelFilter::Debug)
        .parse_env("RUST_LOG")
        .init();
}